package cn.tedu.api;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class T3_SimpleDateFormat {
    public static void main(String[] args) throws ParseException {
        method();//两种类型的 日期数据互转
        method2();//接收用户输入的出生日期，计算存活天数
    }
    public static void method2() throws ParseException {
        String birthday = new Scanner(System.in).nextLine();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-mm-dd");
        Date date1 = sdf1.parse(birthday);
        long birth = date1.getTime();
        long now = System.currentTimeMillis();
        System.out.println((now-birth)/1000/60/60/24);
    }
    public static void method() throws ParseException {
        //1 String类型转成SimpleDateFormat
        String date = "2020-10-21";
        SimpleDateFormat sdf = new SimpleDateFormat(date);
        System.out.println(sdf);
        //2 把String 类型的日期，转成Date类型
        Date d = sdf.parse(date);
        System.out.println(d.getYear());
        System.out.println(d.getMonth());
        System.out.println(d.getDate());
        //把Date类型转成String类型
        Date da = new Date();
        String str = sdf.format(da);
        System.out.println(str);
    }


    }

